package javagprssrv.Task;

import java.util.Date;
import javagprssrv.StructClass.structTask;
import java.text.SimpleDateFormat;
import javagprssrv.JGS_Param;

public class TaskTimeOutManager extends java.lang.Thread
{

    public TaskTimeOutManager() {
        super("TaskTimeOutManager");
    }
    
    @java.lang.Override
    public void run() {
        while (java.lang.Boolean.TRUE) {
            try {
                java.lang.Thread.sleep(5000L);
                final int TaskCount = javagprssrv.JGS_Param.Tasks.size();
                final int TaskFailedSeconds = javagprssrv.JGS_Param._TaskFailedSeconds;
                final java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                synchronized (javagprssrv.JGS_Param.Tasks) {
                    for (int i = TaskCount - 1; i >= 0; --i) {
                        final java.lang.String str_dt_start = javagprssrv.JGS_Param.Tasks.elementAt(i).Task_StartDateTime;
                        final java.util.Date dt_now = new java.util.Date();
                        final java.lang.String str_dt_TaskCreateTime = javagprssrv.JGS_Param.Tasks.elementAt(i)._TaskCreateDateTime;
                        final java.util.Date dt_CreateTime = sdf.parse(str_dt_TaskCreateTime);
                        final int sp_seconds0 = (int)((dt_now.getTime() - dt_CreateTime.getTime()) / 1000L);
                        if (sp_seconds0 > 3600) {
                            final java.lang.String TaskID = javagprssrv.JGS_Param.Tasks.elementAt(i)._TaskID;
                            final java.lang.String TaskState = java.lang.String.valueOf(javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State);
                            javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State = 9;
                            javagprssrv.JGS_Param.Tasks.remove(i);
                            final java.lang.String count = java.lang.String.valueOf(javagprssrv.JGS_Param.Tasks.size());
                            javagprssrv.JGS_Param.myLog.ShowLog("任务(ID=" + TaskID + ",State=" + TaskState + ",_TaskCreateDateTime=" + str_dt_TaskCreateTime + ")超时，已被中止运行！还有" + count + "个Task。", true, true);
                        }
                        if (javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State != 0) {
                            if (javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State != 9) {
                                if (str_dt_start.trim().length() != 0) {
                                    final java.util.Date dt_start = sdf.parse(str_dt_start);
                                    final int sp_seconds2 = (int)((dt_now.getTime() - dt_start.getTime()) / 1000L);
                                    if (sp_seconds2 > TaskFailedSeconds) {
                                        final java.lang.String TaskID2 = javagprssrv.JGS_Param.Tasks.elementAt(i)._TaskID;
                                        final java.lang.String TaskState2 = java.lang.String.valueOf(javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State);
                                        final java.lang.String TaskStartDateTime = javagprssrv.JGS_Param.Tasks.elementAt(i).Task_StartDateTime;
                                        javagprssrv.JGS_Param.Tasks.elementAt(i).Task_State = 9;
                                        javagprssrv.JGS_Param.Tasks.remove(i);
                                        final java.lang.String count2 = java.lang.String.valueOf(javagprssrv.JGS_Param.Tasks.size());
                                        javagprssrv.JGS_Param.myLog.ShowLog("任务(ID=" + TaskID2 + ",State=" + TaskState2 + ",StartDate=" + TaskStartDateTime + ")超时，已被中止运行！还有" + count2 + "个Task。", true, true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (java.lang.Exception e) {}
        }
    }
}
